home *** CD-ROM | disk | FTP | other *** search
- ;void prt(strg,printer_codes);
- ; char *strg,*printer_codes;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
- EXTRN _time_out:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _prt
- _prt proc near
- jmp short start ;jump over local data
- delay dw ? ;
- target dw ? ;
- start: push bp ;
- mov bp,sp ;
- push di ;
- push si ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: mov ah,1 ;BIOS func to init prtr
- sub dx,dx ;choose LPT1
- int 17h ;initialize the prtr port
- sub ax,ax ;clear AX
- mov es,ax ;point ES to 0000:0000
- mov dx,es:[408h] ;get LPT1 base address
- push ds ;save Turbo's DS
- mov _error_code,1 ;1 = printer error
- mov cl,_time_out ;get _time_out seconds
- cmp _memory_model,2 ;data near or far?
- jb A0 ;jump if near
- les di,dword ptr[bp+8] ;ES:DI pts to printer codes
- lds si,dword ptr[bp+4] ;DS:SI pts to Strg
- jmp short A00 ;
- A0: mov ax,ds ;ES = DS
- mov es,ax ;
- mov di,[bp+6] ;NEAR case
- mov si,[bp+4] ;
- A00: sub ax,ax ;
- mov al,cl ;time_out
- or al,al ;don't allow zero
- jnz A1 ;
- mov al,3 ;default to 3 seconds
- A1: mov cl,18 ;18 ticks per second
- mul cl ;
- mov cs:delay,ax ;save count
- cmp byte ptr[si],0 ;test for null string
- je H1 ;
- B1: mov al,[si] ;get a character
- inc si ;forward Strg ptr for next time
- cmp al,0 ;end of string?
- je LX ;
- cmp al,128 ;test if control code
- jb F1 ;jump if below range
- cmp al,159 ;test if above
- ja F1 ;jump if above
- push cx ;save Strg len ctr
- push di ;save array position
- sub al,128 ;count codes from 0
- mov cl,6 ;times six bytes
- mul cl ;offset in PrinterCodes
- add di,ax ;now ES:DI pts to code sequence
- sub cx,cx ;clear CX
- mov cl,es:[di] ;get string descriptor
- jcxz E1 ;quit loop if null
- C1: inc di ;forward ptr
- mov al,es:[di] ;get code character
- call Writeit ;write the code
- or ah,ah ;printer error?
- jnz D1 ;continue if not
- add sp,4 ;balance stack
- jmp short H1 ;quit routine
- D1: loop C1 ;go do next
- E1: pop di ;restore ptr to start of array
- pop cx ;restore Strg len ctr
- jmp short G1 ;go get next char in Strg
- F1: call Writeit ;go write character
- or ah,ah ;proc returned error?
- jz H1 ;quit if so
- G1: jmp short B1 ;go do next char
- LX: pop ds ;
- dec _error_code ;0 = all OK
- jmp short I1 ;
- H1: pop ds ;
- I1: pop si ;
- pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- Writeit PROC
- out dx,al ;send to output data register
- inc dx ;forward to status register
- push cx ;save string counter
- call GetBiosCount ;get timer reading
- mov bx,cx ;make copy
- add cx,cs:delay ;add delay count
- cmp bx,cx ;if timer doesn't turn over...
- jb J1 ;go ahead
- mov cx,cs:delay ;otherwise, extend delay
- J1: mov cs:target,cx ;save target count on stack
- Wait: in al,dx ;get status value
- test al,8 ;test for printer error
- jz Error ;
- test al,80h ;test for Printer Ready
- jnz Ready ;jump if ready
- Error: call GetBiosCount ;
- cmp cx,cs:target ;compare to target
- jb Wait ;
- mov bl,1 ;1 = error
- pop cx ;restore string counter
- mov ah,0 ;return code for failure
- jmp short K1 ;return
- Ready: pop cx ;restore string counter
- inc dx ; output control register
- mov al,13 ;bits for strobe signal
- out dx,al ;send the signal
- dec al ;change to strobe OFF
- out dx,al ;send the signal
- dec dx ;point back to
- dec dx ; base address
- mov ah,1 ;return code for success
- K1: ret ;
- Writeit endp
- GetBIOSCount PROC
- push dx ;return value in CX:DX
- push ax ;
- sub ah,ah ;function number
- int 1ah ;get timer count
- mov cx,dx ;low word in CX
- pop ax ;
- pop dx
- ret
- GetBIOSCount endp
- _prt endp
- _TEXT ENDS
- END